package tgc.edu.ljc.bookmanage.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Transient;

import tgc.edu.ljc.bookmanage.security.SysDept;

@Entity
public class TbClass extends SysDept{
	private String manager;
	private List<Student> students=new ArrayList<>();

	public String getManager() {
		return manager;
	}

	public void setManager(String manager) {
		this.manager = manager;
	}

	@OneToMany(cascade=CascadeType.ALL,mappedBy="tbClass")
	@OrderBy(value="username")
	public List<Student> getStudents() {
		return students;
	}

	public void setStudents(List<Student> students) {
		this.students = students;
	}
	
	@Transient
	public String getParentName() {
		SysDept dept = getParent();
		String str="";
		while(dept!=null) {
			str=dept.getName()+"/"+str;
			dept=dept.getParent();
		}
		if(str.length()>0) {
			str=str.substring(0, str.length()-1);
		}
		return str;
	}
	
}
